package com.longxi.tianjintianbao.ui.adapter.multitype;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.listener.SelectReceiptListListener;
import com.longxi.tianjintianbao.model.ReceiptList;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by cxw on 2018/2/20.
 */
public class ReceiptListViewBinder extends ItemViewBinder<ReceiptList, ReceiptListViewBinder.ViewHolder> {

    SelectReceiptListListener listener;

    public ReceiptListViewBinder(SelectReceiptListListener listener) {
        this.listener = listener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_receipt_list, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull ReceiptList receiptList) {
        holder.mTvReceiptType.setText(receiptList.getType());
        holder.mTvBillDate.setText(receiptList.getBilldate());
        holder.mTvContact.setText(receiptList.getContent());

        holder.mLlBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.onSuccess(receiptList.getBillid(), receiptList.getState());
            }
        });
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        LinearLayout mLlBtn;
        TextView mTvReceiptType;
        TextView mTvBillDate;
        TextView mTvContact;
        TextView mTvDetails;
        ViewHolder(View itemView) {
            super(itemView);
            mLlBtn = itemView.findViewById(R.id.llBtn);
            mTvReceiptType = itemView.findViewById(R.id.tvReceiptType);
            mTvBillDate = itemView.findViewById(R.id.tvBillDate);
            mTvContact = itemView.findViewById(R.id.tvContact);
            mTvDetails = itemView.findViewById(R.id.tvDetails);
        }
    }
}
